// home模块的小仓库

import {requeCategoryList, reqGetBannerList, reqGetFloorList} from "@/api"
// state：仓库存储数据的地方
const state = {
    categoryList: [],
    bannerList :[],
    floorList: []
}
// mutations: 修改state的唯一手段
const mutations = {
    CATEGORYLIST(state, list) {
        state.categoryList = list
    },
    GETBANNERLIST(state, list) {
        state.bannerList = list
    },
    GETFLOORLIST(state, list) {
        state.floorList = list
    },
}

// action: 书写业务逻辑，也可以处理异步
const actions={
    async categoryList({commit}) {
        // 发请求获取数组
        let result = await requeCategoryList()
        if(result.code == 200) {
            commit('CATEGORYLIST', result.data)
        }
    },
    async getBannerList({commit}) {
        let result = await reqGetBannerList()
        if(result.code == 200) {
            commit('GETBANNERLIST', result.data)
        }
    },
    async getFloorList({commit}) {
        let result = await reqGetFloorList()
        if(result.code == 200) {
            commit('GETFLOORLIST', result.data)
        }
    }
    
}

// getters: 可以理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters={}

export default {
    state,
    mutations,
    actions,
    getters
}
